#include "mainwidget.h"
#include "ui_mainwidget.h"
#include "QDebug"


MainWidget::MainWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::MainWidget)
{
    ui->setupUi(this);
    //无边框化
    this->setWindowFlags( Qt::FramelessWindowHint );
    ui->label->hide();
    stackLayout->addWidget(login);  //id0
    stackLayout->addWidget(selectmethod);  //id1
    stackLayout->addWidget(testing);  //id2
    stackLayout->addWidget(methoddevelop);  //id3
    stackLayout->addWidget(settings);    //id4
    stackLayout->addWidget(login2); //id5
    stackLayout->addWidget(registration); //id6

    setLayout(stackLayout);
    //打开页面
    connect(login, &Login::display, stackLayout, &QStackedLayout::setCurrentIndex);
    connect(selectmethod, &SelectMethod::display, stackLayout, &QStackedLayout::setCurrentIndex);
    connect(testing, &Testing::display, stackLayout, &QStackedLayout::setCurrentIndex);
    connect(methoddevelop, &MethodDevelop::display, stackLayout, &QStackedLayout::setCurrentIndex);
    connect(settings, &Settings::display, stackLayout, &QStackedLayout::setCurrentIndex);
    connect(login2, &Login2::display, stackLayout, &QStackedLayout::setCurrentIndex);
    connect(registration, &Registration::display, stackLayout, &QStackedLayout::setCurrentIndex);
    //刷新列表
    connect(registration, &Registration::reset, settings, &Settings::resetListWidget);//让设置页面中的用户列表刷新
    connect(login, &Login::reset, selectmethod, &SelectMethod::resetListWidget);//让选择方法页面中的方法列表刷新
    connect(login2, &Login2::reset, selectmethod, &SelectMethod::resetListWidget);//让选择方法页面中的方法列表刷新
    connect(methoddevelop, &MethodDevelop::reset, selectmethod, &SelectMethod::resetListWidget);//让选择方法页面中的方法列表刷新
    connect(login, &Login::reset, settings, &Settings::resetListWidget_2);//让设置页面中的药品列表刷新
    connect(login2, &Login2::reset, settings, &Settings::resetListWidget_2);//让设置页面中的药品列表刷新
    connect(testing, &Testing::reset, settings, &Settings::resetListWidget_2);//让设置页面中的药品列表刷新
    //方法传送
    connect(selectmethod, &SelectMethod::methodName, testing, &Testing::nameRecevier);//将方法列表里选中的方法名传送给测试页面
    //管理权限
    connect(login, &Login::admin, selectmethod, &SelectMethod::hiding);//让选择方法页面里的管理员相关内容出现或者消失
    connect(login, &Login::admin, methoddevelop, &MethodDevelop::hiding);//让选择方法页面里的管理员相关内容出现或者消失
    connect(login, &Login::admin, testing, &Testing::hiding);//让选择方法页面里的管理员相关内容出现或者消失
    connect(login2, &Login2::admin, selectmethod, &SelectMethod::hiding);//让选择方法页面里的管理员相关内容出现或者消失
    connect(login2, &Login2::admin, methoddevelop, &MethodDevelop::hiding);//让选择方法页面里的管理员相关内容出现或者消失
    connect(login2, &Login2::admin, testing, &Testing::hiding);//让选择方法页面里的管理员相关内容出现或者消失
    //WiFi标识显示
    connect(settings, &Settings::wifi, this, &MainWidget::wifishow);//让WiFi标识显示或消失
    //检测当前WiFi是否连接
    QNetworkConfigurationManager mgr;
    if(mgr.isOnline()){             //wifi已连接
        ui->label->show();
    }
    else{
        ui->label->hide();
    }
}

MainWidget::~MainWidget()
{
    delete ui;
}


//电池数据显示
void MainWidget::on_progressBar_valueChanged(int value)
{
    ui->progressBar->setValue(value);
}

//WiFi标识显示
void MainWidget::wifishow(bool num)
{
    if(num == true){
         ui->label->show();
    }else{
        ui->label->hide();
    }

}

